/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.dataaccess.hibernate;

import cms.dataaccess.ReviewContentsDAO;
import cms.exceptions.HibernateAccessLayerException;
import dto.Reviewcontents;
import java.util.List;

/**
 *
 * @author Gary
 */
class ReviewContentsDAOImpl extends AbstractDAO implements ReviewContentsDAO {

    public ReviewContentsDAOImpl() {
        super();
    }

    @Override
    public Reviewcontents getReviewContent(String contentNo) {
          try{
            return (Reviewcontents) super.find(Reviewcontents.class, contentNo);
        } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public List<Reviewcontents> getReviewContentByCategory(String contentCategory) {
          try{
            return   super.findByCustomizeQuery(Reviewcontents.class, " contentCategory='"+contentCategory+"'");
        } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public List<Reviewcontents> getAllReviewContents() {
            try{
            return   super.findAll(Reviewcontents.class);
        } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public boolean updateReviewContents(Reviewcontents reviewContent) {
        
        if(reviewContent==null) {
            return  false;
        }
           try{
                super.saveOrUpdate(reviewContent);
                return true;
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public boolean deleteReviewContents(String contentNo) {
          if(contentNo==null) {
            return  false;
        }
               try{
                   
                 if(this.getReviewContent(contentNo)==null) {
                  return false;
                 }
                super.delete(this.getReviewContent(contentNo));
                return true;
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
        }
    }
    
}
